<?php

namespace App\Http\Controllers\Logic;

use App\Http\Controllers\Controller;
use App\Model\OAStaff;
use App\Model\OASupplier;
use Illuminate\Http\Request;

class LoginLogic extends Controller
{
    public function verifyLogin($input){

        if($input['is_company']){
            $staff = OAStaff::query()->where('account',$input['account'])
                ->where('password',md5($input['password']))
                ->first();
            if(!$staff) throw new \Exception('用户'.$input['account'].'不存在或登录密码错误');
            return ['uid'=>$staff->id,'username'=>$staff->username,'is_company'=>1];
        }else{
        $supplier = OASupplier::query()->where('account',$input['account'])
            ->where('password',md5($input['password']))
            ->first();
            if(!$supplier) throw new \Exception('供应商'.$input['account'].'不存在或登录密码错误');
            return ['uid'=>$supplier->id,'username'=>$supplier->username,'is_company'=>$input['is_company'],'position_id'=>228];

        }


    }
}
